const LogWriter = require('./writelog');

// 获取命令行参数
const [,, host = 'localhost', port = '9222'] = process.argv;

// 创建LogWriter实例
const logger = new LogWriter(host, port);

// 错误处理
process.on('uncaughtException', (err) => {
  console.error('未捕获的错误:', err);
  process.exit(1);
});

process.on('SIGINT', () => {
  console.log('\n正在关闭连接...');
  logger.disconnect().then(() => {
    process.exit(0);
  });
});

// 连接到目标
logger.connect().catch(err => {
  console.error('连接错误:', err);
  process.exit(1);
});

console.log(`正在连接到 ${host}:${port}...`);